/*
 * @Description: 描述信息
 * @Version: 版本号
 * @Author: xuebao
 * @Date: 2023-12-11 18:07:58
 * @LastEditors: xuebao
 * @LastEditTime: 2023-12-15 11:58:43
 */
import { create } from 'zustand'

import { User } from '@/types/api'
import { getItem } from '@/utils/storage'
export const useStore = create<{
  token: string,
  userInfo: User.UserItem,
  isDark: boolean,
  updateUserInfo: (userInfo: User.UserItem) => void,
  updateToken: (token: string) => void,
  updateTheme: (isDark: boolean) => void,
  collapse: boolean,
  updateCollapse: () => void
}>((set) => ({
  isDark: getItem('isDark') || false,
  token: '',
  collapse: false,
  userInfo: {
    "_id": '',
    userId: 0,
    "userName": '',
    "userEmail": '',
    "mobile": '',
    "deptId": '',
    "deptName": '',
    "job": '',
    "state": 0,
    "role": 0,
    "roleList": [],
    "createId": 0,
    "userImg": ''
  },
  updateTheme: isDark => set({ isDark }),
  // increaseAdd: () => set((state) => ({ count: state.count + 1 }))
  updateUserInfo(userInfo: User.UserItem) {
    set({ userInfo })
  },
  updateToken: (token: string) => set({ token }),
  updateCollapse: () => set(state => {
    return {
      collapse: !state.collapse
    }
  }
  )
}))
